import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ChiHuoLianMeng {
    public static List<String> names=new ArrayList<String>();//订餐姓名
    public static List<String> disMegs=new ArrayList<String>();//所选信息
    public static List<Integer> times=new ArrayList<Integer>();//送餐时间
    public static List<String> addresses=new ArrayList<String>();//送餐地址
    public static List<Integer> states=new ArrayList<Integer>();//订餐状态0表示预定1表示完成
    static {
        states.add(0);
        states.add(0);
        states.add(0);
        states.add(0);
        states.add(0);
    }
    public static List<Integer> sumPrices=new ArrayList<Integer>();//订单总金额
    public static List<String> dishNames=new ArrayList<String>();//菜品名称
    static {
        dishNames.add("红烧鱼");
        dishNames.add("鱼香肉丝");
        dishNames.add("青椒毛豆");
    }
    public static List<Integer> prices=new ArrayList<Integer>();//菜品单价
    static {
        prices.add(38);
        prices.add(20);
        prices.add(10);
    }
    public static List<Integer> praiseNums=new ArrayList<Integer>();//点赞数
    static {
        praiseNums.add(2);
        praiseNums.add(5);
        praiseNums.add(26);
    }
    //主菜单
    public static void Menu(){
        Scanner input = new Scanner(System.in);
        System.out.println("欢迎使用吃货联盟订餐系统");
        System.out.println("======================");
        System.out.println("1.我要订餐");
        System.out.println("2.查看餐袋");
        System.out.println("3.签收订单");
        System.out.println("4.删除订单");
        System.out.println("5.我要点赞");
        System.out.println("6.退出系统");
        System.out.println("======================");
        System.out.println("请输入你需要的操作");
        System.out.println("请选择：");
        int id = input.nextInt();
        /*while (!input.hasNextInt()){
            input=new Scanner(System.in);
            System.out.println("请重新输入有效值：");
            id=input.nextInt();
        }*/
        switch (id) {
            case 1:
                OrderMeal();
                break;
            case 2:
                CheckOrder();
                break;
            case 3:
                SignOrder();
                break;
            case 4:
                DeleteOrder();
                break;
            case 5:
                EasyLike();
                break;
            case 6:
                ExitSystem();
                break;
            default:
                System.out.println("欢迎光临");
                break;
        }
    }
    //我要订餐
    public static void OrderMeal() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("***我要订餐***");
            System.out.println("请输入订餐人姓名");
            String name = scanner.next();
            System.out.println("序号" + "\t" + "菜名" + "\t" + "单价" + "\t" + "点赞数");
            for (int j = 0; j < dishNames.size(); j++) {

                System.out.println((j + 1) + "\t" + dishNames.get(j) + "\t" + prices.get(j) + "\t" + praiseNums.get(j));
            }
            System.out.println("请输入你要点的菜品编号：");
            int chooseDish = scanner.nextInt();
            System.out.println("请输入你需要的份数：");
            int number = scanner.nextInt();
            String dishMeg = dishNames.get(chooseDish - 1) + " " + number + "份";
            int money = prices.get(chooseDish - 1) * number;
            int money1 = (money >= 50) ? 0 : 5;

            System.out.println("请输入送餐时间（10点到20点整之间）:");
            int time = scanner.nextInt();
            while (time < 10 || time > 20) {
                System.out.println("你输入的时间点不在配送范围内，请重新输入：");
                time = scanner.nextInt();
            }

            System.out.println("请输入送餐地址:");
            String address = scanner.next();

            System.out.println("订餐成功！");
            System.out.println("您订的是:" + dishMeg);
            System.out.println("送餐时间:" + time + "点");
            System.out.println("您的餐费:" + money + "元，配送费:" + money1 + "元，总计:" + (money + money1) + "元");

            names.add(name);
            disMegs.add(dishMeg);
            times.add(time);
            addresses.add(address);
            sumPrices.add(money + money1);

            System.out.println("按0返回主菜单否则退出系统");
            int num = scanner.nextInt();
            if (num == 0) {
                Menu();
            } else {
                System.out.println("谢谢使用！");
                System.exit(1);
            }
            System.exit(1);
        }


    //查看惨袋
    public static void CheckOrder(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("***查看餐袋***");
        System.out.println("序号\t订餐人\t商品信息\t送餐时间\t送餐地址\t\t总金额\t订单状态");
        for (int i = 0; i <names.size(); i++) {
            String state=null;
            if (states.get(i)==0){
                 state="已经预定";
            }else {
                state="已经完成";
            }
            String Sumprices=sumPrices.get(i)+"元";
            System.out.println((i+1)+"\t\t"+names.get(i)+"\t"+disMegs.get(i)+"\t"+times.get(i)+"点\t"+
                    addresses.get(i)+"\t\t"+Sumprices+"\t"+state);
        }
        System.out.println("按0返回主菜单否则退出系统");
        int num=scanner.nextInt();
        if (num==0){
            Menu();
        }else {
            System.out.println("谢谢使用！");
        }
    }
    //签收订单
    public static void SignOrder(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("***签收订单***");
        System.out.println("请选择要签收的订单序号:");
        boolean falg=false;
        int id=scanner.nextInt();

        for (int i = 0; i <names.size() ; i++) {
            if (names.get(i)!=null&&states.get(i)==0&&id==i+1 ){
                states.set(i,1);
                System.out.println("签收成功");
                falg=true;
            }else if (names.get(i)!=null&&states.get(i)==1&&id==i+1){
                System.out.println("你的订单已经签收不能再次牵收");
                falg=true;
            }
           break;
        }
        if (!falg){
            System.out.println("对不起你查找的订单不存在！");
        }
        System.out.println("按0返回主菜单否则退出系统");
        int num=scanner.nextInt();
        if (num==0){
            ChiHuoLianMeng.Menu();
        }else {
            System.out.println("谢谢使用！");
        }
    }

    //删除订单
    public static void DeleteOrder(){
        System.out.println("***删除订单***");
        boolean falg=false;
        System.out.println("请输入要删除的订单序号:");
        Scanner input =new Scanner(System.in);
        int id = input.nextInt();
        for (int i = 0; i <names.size() ; i++) {
            if (names.get(i)!=null&&states.get(i)==1&&id==i+1){
                falg=true;
               names.remove(i);
               disMegs.remove(i);
               times.remove(i);
               addresses.remove(i);
               states.remove(i);
               sumPrices.remove(i);
                System.out.println("删除订单成功！");
            }else if (names.get(i)!=null&&states.get(i)==0&&id==i+1){
                System.out.println("你的订单还没有签收，不能删除！");
                falg=true;
            }
        }
        if (!falg){
            System.out.println("你要删除的订单不存在");
        }
        System.out.println("按0返回主菜单否则退出系统");
        int num=input.nextInt();
        if (num==0){
            Menu();
        }else {
            System.out.println("谢谢使用！");
        }

    }
    //我要点赞
    public static void EasyLike(){
        System.out.println("***我要点赞***");
        Scanner input = new Scanner(System.in);
        System.out.println("序号"+"\t"+"菜名"+"\t"+"单价");
        for (int i = 0; i <dishNames.size() ; i++) {
            String nums=(praiseNums.get(i))>0?praiseNums.get(i)+"赞":"";
            System.out.println((i+1)+"\t"+dishNames.get(i)+"\t"+prices.get(i)+"元\t"+nums);
        }
        System.out.println("请输入你要点赞的菜品序号");
        int id=input.nextInt();
        int num=praiseNums.get(id-1);
        praiseNums.set(id-1,num+1);
        System.out.println("点赞成功！");
        System.out.println("按0返回主菜单否则退出系统");
        int num1=input.nextInt();
        if (num1==0){
            Menu();
        }else {
            System.out.println("谢谢使用！");
        }
    }
    //退出系统
    public static void ExitSystem(){
        System.out.println("欢迎光临！");
        System.exit(1);
    }
}
